<template>
	<div class="forgetview allbgc">
		<div class="logview-top logreg-top alltop">
			<span>
				<router-link to="/log">
					<</router-link> </span> <p>
						<span>
							请重置密码
						</span>
						</p>
		</div>

		<div class="forgetview-main">
			<div class="forgetview-from logreg-from">
				<label><input type="text" placeholder="填写手机号" v-model="username" /></label>
				<label><input type="password" placeholder="请输入新设置的密码" v-model="password" /></label>
				<label><input type="password" placeholder="请输入验证码" v-model="vercode" /><button>发送验证码</button></label>
			</div>
			<div class="photo">
				<button>
					<router-link to="/log">去登录</router-link>
				</button>
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
				password: '',
				vercode: ''
			}
		},
		methods: {
			reg() {
				console.log(this.username)
				if (this.username == "") {
					this.$toast('手机号不能为空');
					return false
				}
				if (this.password == "") {
					this.$toast('密码不能为空');
					return false
				}
				if (this.vercode == "") {
					this.$toast('请输入验证码');
					return false
				}
				this.$http.post("/user/forget", this.qs.stringify({
					username: this.username,
					password: this.password,
					vercode: this.vercode,
				})).then(res => {
					console.log(res)
					this.$toast('密码已重置');
					this.$router.push('log')
				}).catch(err => {
					console.log(err)
					console.log(err.response.status)
					if (err.response.status == 409) {
						this.$toast('用户名未注册');
					}
					if (err.response.status == 401) {
						this.$toast('网络异常,请稍后重试');
					}
				})
			}
		}
	}
</script>

<style>
	.forgetview-from label button {
		top: 113px;
	}

	.forgetview-main a {
		color: #fff;
	}
</style>
